// HeapGrowthPID.java
// Jeremy Singer
// 6 Sep 11

/**
 * Simple PID controller to experiment with
 * heap growth events in Jikes RVM.
 * Instantiated by HeapGrowthManager in the
 * bootimage writer. The parameters
 * kp, ki, kd, and target can be controlled
 * by Jikes RVM startup command line params:
 * e.g.
 * ./rvm -X:gc:konstantp=0.5 -X:gc:konstanti=0.2  \
 *  -X:gc:konstantd=0.0 -X:gc:konstanttarget = 0.9
 */

package org.mmtk.utility.heap;

public class HeapGrowthPID extends PID {

  // cached value of measured variable
  private double outputVal;

  public HeapGrowthPID(double kp, double ki, double kd, double target) {
    super(kp, ki, kd, target);
    this.outputVal = 0;
  }

  /**
   * runs a single iteration of the PID controller equation, for 
   * time-step dt. Also updates the locally cached value of
   * the measured variable outputVal.
   */
  public void runOneIter(long dt, double outputVal) {
    this.outputVal = outputVal;
    runOneIter(dt);
  }

  /**
   * reads current value of output variable (measured variable)
   * Issue - for modularity reasons we do't actually have access to
   * heap stats inside PID controller itself. So, what actually happens is
   * that the output variable value is cached in an instance field, but
   * the cached value is updated by the {@link HeapGrowthManager}
   * every time it calls {@link runOneIter}.
   */
  public double readCurrentOutputVal() {
    return this.outputVal;
  }



}